<?php
if (isset($_POST['action'])) {
    switch ($_POST['action']) {
        case "Save Changes":
            $dataHash = showEmployeeInfo($_SESSION['userName'], $_SESSION['userPassHash'], $_POST['accName'])[2];
            $modifyEmployeeResult = modifyEmployee(
                    $_SESSION['userName'], $_SESSION['userPassHash'], $_POST['accName'], $dataHash, $_POST['empFname'], $_POST['empLname'], $_POST['startDate'], $_POST['endDate'], $_POST['empStatus'], $_POST['address'], $_POST['email'], $_POST['phoneNum'], $_POST['wage']);
            break;
        case "Delete Account":
            $accountHash = getAccount(
                            $_POST['accName'], $_SESSION['userName'], $_SESSION['userPassHash'])['results']['dataHash'];
            $deleteAccountResult = deleteAccount(
                    $_POST['accName'], $_SESSION['userName'], $_SESSION['userPassHash'], $accountHash);
            break;
    }
}

$allEmployeeInfo = getAllEmployeeDetails($_SESSION['userName'], $_SESSION['userPassHash']);
?>
<h3>Employee Manager</h3>
<div class="accordion" id="employeesAccordion">
    <?php
    foreach ($allEmployeeInfo[1] as $employeeInfo) {
        ?><div class="accordion-group">
            <div class="accordion-heading">
                <a class="accordion-toggle" data-toggle="collapse" data-parent="#employeesAccordion"
                   <?php echo("href=\"#" . $employeeInfo['accName'] . "\""); ?>><?php echo($employeeInfo['accName']); ?></a></div>
            <div <?php echo('id="' . $employeeInfo['accName'] . '"'); ?> class="accordion-body collapse">
                <div class="accordion-inner">
                    <form action="" method="post">
                        <input <?php echo("id=\"txtAccName" . $employeeInfo['accName'] . "\""); ?> type="hidden" name="accName" value="<?php echo($employeeInfo['accName']); ?>" />
                        <div class="controls-row">
                            <div class="control-group span3">
                                <label class="control-label" <?php echo("id=\"lblEmpFname" . $employeeInfo['accName'] . "\""); ?> <?php echo("for=\"txtEmpFname" . $employeeInfo['empFname'] . "\""); ?>>First Name</label>
                                <div class="controls">
                                    <input <?php echo("id=\"txtEmpFname" . $employeeInfo['accName'] . "\""); ?> type="text" name="empFname" value="<?php echo($employeeInfo['empFname']); ?>" REQUIRED />
                                </div>      
                            </div>
                            <div class="control-group span3">
                                <label class="control-label" <?php echo("id=\"lblEmpLname" . $employeeInfo['accName'] . "\""); ?> <?php echo("for=\"txtEmpLname" . $employeeInfo['empLname'] . "\""); ?>>Last Name</label>
                                <div class="controls">
                                    <input <?php echo("id=\"txtEmpLname" . $employeeInfo['accName'] . "\""); ?> type="text" name="empLname" value="<?php echo($employeeInfo['empLname']); ?>" REQUIRED />
                                </div>      
                            </div>
                            <div class="control-group span3">
                                <label <?php echo("id=\"lblEmpStatus" . $employeeInfo['accName'] . "\""); ?> <?php echo("for=\"empStatus" . $employeeInfo['accName'] . "\""); ?>>Status</label>
                                <div class="controls">
                                    <select <?php echo("id=\"empStatus" . $employeeInfo['accName'] . "\""); ?> name="empStatus" >
                                        <option value="Manager" <?php if ($employeeInfo['empStatus'] == "Manager") echo("SELECTED"); ?>>Manager</option>
                                        <option value="Worker" <?php if ($employeeInfo['empStatus'] == "Worker") echo("SELECTED"); ?>>Worker</option>
                                    </select>
                                </div>      
                            </div>
                        </div>
                        <div class="controls controls-row">
                            <div class="control-group span3">
                                <label <?php echo("id=\"lblAddress" . $employeeInfo['accName'] . "\""); ?> <?php echo("for=\"txtAddress" . $employeeInfo['accName'] . "\""); ?>>Address</label>
                                <div class="controls">
                                    <input <?php echo("id=\"txtAddress" . $employeeInfo['accName'] . "\""); ?> type="text" name="address" value="<?php echo($employeeInfo['address']); ?>" REQUIRED />
                                </div>
                            </div>
                            <div class="control-group span3">
                                <label <?php echo("id=\"lblEmail" . $employeeInfo['accName'] . "\""); ?> <?php echo("for=\"txtEmail" . $employeeInfo['email'] . "\""); ?>>Email</label>
                                <div class="controls">
                                    <input <?php echo("id=\"txtEmail" . $employeeInfo['accName'] . "\""); ?> type="text" name="email" value="<?php echo($employeeInfo['email']); ?>" REQUIRED />
                                </div>      
                            </div>
                            <div class="control-group span3">
                                <label <?php echo("id=\"lblPhoneNum" . $employeeInfo['accName'] . "\""); ?> <?php echo("for=\"txtPhoneNum" . $employeeInfo['phoneNum'] . "\""); ?>>Phone Number</label>
                                <div class="controls">
                                    <input <?php echo("id=\"txtPhoneNum" . $employeeInfo['accName'] . "\""); ?> type="text" name="phoneNum" value="<?php echo($employeeInfo['phoneNum']); ?>" REQUIRED />
                                </div>      
                            </div>
                        </div>
                        <div class="controls controls-row">
                            <div class="control-group span3">
                                <label <?php echo("id=\"lblStartDate" . $employeeInfo['accName'] . "\""); ?> <?php echo("for=\"txtStartDate" . $employeeInfo['startDate'] . "\""); ?>>Start Date</label>
                                <div class="controls">
                                    <input class="datepicker " <?php echo("id=\"txtStartDate" . $employeeInfo['accName'] . "\""); ?> type="text" name="startDate" value="<?php echo($employeeInfo['startDate']); ?>" REQUIRED />
                                </div>
                            </div>
                            <div class="control-group span3">
                                <label <?php echo("id=\"lblEndDate" . $employeeInfo['accName'] . "\""); ?> <?php echo("for=\"txtEndDate" . $employeeInfo['endDate'] . "\""); ?>>End Date</label>
                                <div class="controls">
                                    <input class="datepicker" <?php echo("id=\"txtEndDate" . $employeeInfo['accName'] . "\""); ?> type="text" name="endDate" value="<?php echo($employeeInfo['endDate']); ?>" />
                                </div>      
                            </div>
                            <div class="control-group span3">
                                <label <?php echo("id=\"lblWage" . $employeeInfo['accName'] . "\""); ?> <?php echo("for=\"txtWage" . $employeeInfo['wage'] . "\""); ?>>Wage</label>
                                <div class="controls">
                                    <input class="span4" <?php echo("id=\"txtWage" . $employeeInfo['accName'] . "\""); ?> type="text" name="wage" value="<?php echo($employeeInfo['wage']); ?>" REQUIRED />
                                </div>      
                            </div>
                        </div>
                        <div class="controls controls-row">
                            <div class="control-group">
                                <div class="controls">
                                    <input class="btn btn-primary" type="submit" name="action" value="Save Changes" />
                                    <input class="btn" type="submit" name="action" value="Delete Account" />            
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
        <?php
    }
    ?>
</div>